package com.csthink.auditlog.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

/**
 * @author <a href="mailto:security.2009@live.cn">Mars</a>
 * @since 2023-09-12
 */
@Setter
@Getter
@JsonIgnoreProperties(ignoreUnknown = true)
public class Change {
    private String type;

    private String id;

    private String keyword;

    @JsonIgnore
    private Object rawOldValue;

    @JsonProperty("rawOldValue")
    private String rawOldValueStr;

    @JsonIgnore
    private Object rawNewValue;

    @JsonProperty("rawNewValue")
    private String rawNewValueStr;

    @JsonIgnore
    private List<KeyValue> oldValue;

    @JsonProperty("oldValue")
    private String oldValueStr;

    @JsonIgnore
    private List<KeyValue> newValue;

    @JsonProperty("newValue")
    private String newValueStr;


    /**
     * This is for ES. We should generate JSON like this:
     * {"key": k1, "value", v1}, so we can easily search value in ES.
     */
    @AllArgsConstructor
    @NoArgsConstructor
    @Getter
    @Setter
    public static class KeyValue {
        private String key;
        private Object value;
    }
}
